home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / CW CDEV Framework / Framework / CDEVMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-09  |  1.5 KB  |  65 lines  |  [TEXT/MMCC]

  1. #include <A4Stuff.h>
  2. #include <Devices.h>
  3. #include "CDEVClass.h"
  4.  
  5. // declared in CDEV.c
  6. extern long runable(void);
  7. extern cdevObj *makeCDEV(short numItems,DialogPtr cp);
  8.  
  9. // main entry point for control panel
  10. pascal long main(short message,short item,short numItems,short privateValue,
  11.                  EventRecord *e,cdevObj *cdev,DialogPtr d)
  12. {
  13.     // set up a4 so we can access the globals
  14.     long oldA4=SetCurrentA4();
  15.     
  16.     // return code
  17.     long     result=0;
  18.     
  19.     switch (message) {
  20.         // do initialization
  21.         case initDev:
  22.             if ((long)cdev == cdevUnset)
  23.                 cdev=makeCDEV(numItems,d);
  24.             break;
  25.                 
  26.         // control panel is closing
  27.         case closeDev:
  28.             result=cdevUnset;
  29.             break;
  30.         
  31.         // can we run? return 1 if so, else 0
  32.         case macDev:
  33.             result=runable();
  34.             break;
  35.         
  36.         // it's not an init, open, or close message
  37.         default:
  38.             if ((long)cdev != cdevUnset) {
  39.                 // copy over this event and call the action proc
  40.                 cdev->e=e;            
  41.                 result=cdev->actions(message,item);
  42.             }
  43.             break;
  44.     }
  45.     
  46.     // if there is no error code then make sure we return
  47.     // the cdev as the result, as per IM:MMT pg 8-30
  48.     if (result == 0)
  49.         result=(long)cdev;
  50.     else {
  51.         // there's either an err, or we are closing.  In either case, delete the cdev
  52.         delete cdev;
  53.         
  54.         // if we are deleting then result is cdevUnset and there is no err.  Otherwise it
  55.         // must be an error code returned by one of the functions.  Set the result to 1
  56.         // to error out
  57.         if (result != cdevUnset)
  58.             result=1;
  59.     }
  60.     
  61.     // restore a4 before exiting
  62.     SetA4(oldA4);
  63.         
  64.     return(result);
  65. }